﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CourseArraging.Common; 
using CourseArraging.Frm.bbxx;

namespace CourseArraging.Frm.xygl
{
    /// <summary>
    /// 版权所有
    /// 石世特@温州医学院 sst330381@gmail.com
    /// </summary> 
    public partial class FrmStuList : FrmToolbarBase
    {
        #region 字段属性
        private static FrmStuList instance;
        YhxxService.YhxxServiceClient yhxxdao = new YhxxService.YhxxServiceClient();
        private bool isArranged;
        #endregion

        #region 构造器

        /// <summary>
        /// 单例模式
        /// </summary>
        /// <param name="isArranged">是否安排</param>
        /// <returns></returns>
        public static FrmStuList GetInstance(bool isArranged)
        {
            if (instance == null || instance.IsDisposed)
            {
                instance = new FrmStuList(isArranged);
                instance.MdiParent = GlobalVar.frmMain;
            }
            instance.BringToFront();
            return instance;
        }

        public FrmStuList(bool isArranged)
        {
            InitializeComponent();
            this.isArranged = isArranged;
            this.dataGridView1.CellDoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellDoubleClick);
            if (isArranged)
                showStuContact(null);
            else
                showStuContact("未安排");
        }

        #endregion

        #region 事件

        void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0) return;
            FrmStuInfo frmstuinfo = new FrmStuInfo(
                dataGridView1.Rows[e.RowIndex].Cells["学员信息流水"].Value.ToString());
            frmstuinfo.SearchOK += () => { showStuContact(isArranged?null:"未安排"); };
            frmstuinfo.ShowDialog();
        }

        #endregion

        #region 抽象方法实现
        public override void tsb_new_fun()
        {
            FrmStuInfo frm = new FrmStuInfo();
            frm.ShowDialog();
            showStuContact(isArranged ? null : "未安排");
        }
        public override void tsb_refresh_fun()
        {
            showStuContact(isArranged ? null : "未安排");
        }
        public override void tsb_search_fun()
        {
            FrmStuCondi frm = new FrmStuCondi(isArranged);
            frm.SearchOK += (dt) =>
                {
                    this.dataGridView1.DataSource = dt;
                };
            frm.ShowDialog();
        }
        public override void tsb_print_fun()
        {
            DataTable dt = new DataTable();
            if (isArranged)
                dt = yhxxdao.GetStuInfo(null);
            else
                dt = yhxxdao.GetStuInfo("未安排");

            FrmStuBb frmStuBb = new FrmStuBb(dt);
            frmStuBb.ShowDialog();
        }
        #endregion

        #region 方法
        //显示信息 && 刷新信息
        public void showStuContact(string zt)
        {
            this.dataGridView1.DataSource = yhxxdao.GetStuInfo(zt);
            if (this.dataGridView1.DataSource == null) return;
            this.dataGridView1.Columns["学员信息流水"].Visible = false;
            this.dataGridView1.Columns["分校编号"].Visible = false;
        }

        #endregion


    }
}
